/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sree.tali.common;

import com.sree.tali.plugin.HibernatePlugin;
import com.sree.tali.pojo.ArticleTypes;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author sreenuv
 */
public class ArtilceTypesConstants {
    
  private Configuration config;
  private SessionFactory factory;
  private String path = "/hbms/hibernate.cfg.xml";
  private static Class clazz = HibernatePlugin.class;
  public static final String KEY_NAME = clazz.getName();
  
  public void ArtilceTypesConstants()
  {
    try
    {
      URL localURL = HibernatePlugin.class.getResource(this.path);
      this.config = new Configuration().configure(this.path);
      this.factory = this.config.buildSessionFactory();
      System.out.println("Session is ================== " + factory.openSession());
    }
    catch (HibernateException localHibernateException)
    {
      localHibernateException.printStackTrace();
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
    
    
    
    public List<String> getArticleTypes()
    {
        List<String> articleType = new ArrayList<String>();
        if(factory!=null)
        {
          Session session = factory.openSession();
      String qry= "from ArticleTypes";
      Query query =session.createQuery(qry);
      List<ArticleTypes> articletypes = query.list();
      for(ArticleTypes type :articletypes )
      {
          articleType.add(type.getArticleType());
      }
      return articleType ;  
        }
     /*   articleType.add("JAVA");
        articleType.add("JDBC");
        articleType.add("SERVLETS");
        articleType.add("JSP");
        articleType.add("JSTL");
        articleType.add("JSM");
        articleType.add("AJAX");
        articleType.add("XML");
        articleType.add("STRUTS");
        articleType.add("STRUTS2");
        articleType.add("HIBERNATE");
        articleType.add("SPRING");
        articleType.add("IBATIS");
        articleType.add("JSF");
        /*articleType.add("");
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();
        articleType.add();*/
          
          
          
        return articleType;
    }
}
